package com.shunde.xunjian.mapper.ruoyi;


import com.shunde.xunjian.entity.ruoyi.Params.UserDept;
import com.shunde.xunjian.entity.ruoyi.UserInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface UserInfoMapper {

    @Select("SELECT * FROM (SELECT U.*,D.dept_id AS 三级部门ID,D.dept_name AS 三级部门名称 FROM `sys_user` AS U LEFT JOIN sys_dept AS D ON D.dept_id = U.dept_id WHERE U.user_id =  #{user_id}) AS RES1, (SELECT GROUP_CONCAT(UP.post_id) AS 岗位ID,GROUP_CONCAT(P.post_name) AS 岗位名称 FROM sys_user_post AS UP LEFT JOIN sys_post AS P ON (P.post_id = UP.post_id) WHERE user_id =  #{user_id} ) AS RES5,  (SELECT dept_id AS 二级部门ID,dept_name AS 二级部门名称 FROM sys_dept WHERE dept_id = (SELECT D.parent_id FROM `sys_user` AS U LEFT JOIN sys_dept AS D ON D.dept_id = U.dept_id WHERE U.user_id =  #{user_id})) AS RES2, (SELECT R.role_id AS 角色ID,R.role_name AS 角色名称 FROM sys_user_role AS UR LEFT JOIN sys_role AS R ON (R.role_id = UR.role_id) WHERE user_id =  #{user_id}) AS RES3, (SELECT \tGROUP_CONCAT(M.perms) AS 权限列表 FROM \tsys_role_menu AS RM \tLEFT JOIN sys_menu AS M ON ( RM.menu_id = M.menu_id )WHERE RM.role_id = \t( \tSELECT \t\tR.role_id\tFROM \t\tsys_user_role AS UR \t\tLEFT JOIN sys_role AS R ON ( R.role_id = UR.role_id )\tWHERE \tuser_id =  #{user_id})) AS RES4; ")
    UserInfo getUserInfo(@Param("user_id") Long user_id);

    @Select("SELECT U.user_id,U.user_name,D.dept_name FROM `sys_user` AS U LEFT JOIN sys_dept AS D ON D.dept_id = U.dept_id")
    List<UserDept> getUserDept();
}
